/*
 * @Author: 小豪
 * @Description:
 * @Date: 2024-04-10 18:17:49
 * @LastEditTime: 2024-05-23 11:15:49
 * @FilePath: \bsct\gohub\app\http\middlewares\guest_jwt.go
 */
package middlewares

import (
	"github.com/gin-gonic/gin"
	"gohub/pkg/jwt"
	"gohub/pkg/response"
	"time"
)

// GuestJWT 强制使用游客身份访问
func GuestJWT() gin.HandlerFunc {
	return func(c *gin.Context) {

		if len(c.GetHeader("Authorization")) > 0 {

			// 解析 token 成功，说明登录成功了
			_, err := jwt.NewJWT().ParserToken(c)
			if err == nil {
				response.Unauthorized(c, gin.H{
					"success":    false,
					"total_page": "",
					"status":     "100",
					"msg":        "请使用游客身份访问",
					"data":       map[string]string{},
					"time":       time.Now().Unix(),
				})
				return
				// response.Unauthorized(c, "请使用游客身份访问")
				// c.Abort()
				// return
			}
		}

		c.Next()
	}
}
